/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package lego.impl;

import java.util.Collection;

import lego.LegoPackage;
import lego.PicoNet;
import lego.Robot;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectResolvingEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Pico Net</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link lego.impl.PicoNetImpl#getMaster <em>Master</em>}</li>
 *   <li>{@link lego.impl.PicoNetImpl#getSlaves <em>Slaves</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class PicoNetImpl extends EObjectImpl implements PicoNet {
	/**
	 * The cached value of the '{@link #getMaster() <em>Master</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMaster()
	 * @generated
	 * @ordered
	 */
	protected Robot master;

	/**
	 * The cached value of the '{@link #getSlaves() <em>Slaves</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSlaves()
	 * @generated
	 * @ordered
	 */
	protected EList<Robot> slaves;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected PicoNetImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return LegoPackage.Literals.PICO_NET;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Robot getMaster() {
		if (master != null && master.eIsProxy()) {
			InternalEObject oldMaster = (InternalEObject)master;
			master = (Robot)eResolveProxy(oldMaster);
			if (master != oldMaster) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, LegoPackage.PICO_NET__MASTER, oldMaster, master));
			}
		}
		return master;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Robot basicGetMaster() {
		return master;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMaster(Robot newMaster) {
		Robot oldMaster = master;
		master = newMaster;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, LegoPackage.PICO_NET__MASTER, oldMaster, master));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Robot> getSlaves() {
		if (slaves == null) {
			slaves = new EObjectResolvingEList<Robot>(Robot.class, this, LegoPackage.PICO_NET__SLAVES);
		}
		return slaves;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case LegoPackage.PICO_NET__MASTER:
				if (resolve) return getMaster();
				return basicGetMaster();
			case LegoPackage.PICO_NET__SLAVES:
				return getSlaves();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case LegoPackage.PICO_NET__MASTER:
				setMaster((Robot)newValue);
				return;
			case LegoPackage.PICO_NET__SLAVES:
				getSlaves().clear();
				getSlaves().addAll((Collection<? extends Robot>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case LegoPackage.PICO_NET__MASTER:
				setMaster((Robot)null);
				return;
			case LegoPackage.PICO_NET__SLAVES:
				getSlaves().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case LegoPackage.PICO_NET__MASTER:
				return master != null;
			case LegoPackage.PICO_NET__SLAVES:
				return slaves != null && !slaves.isEmpty();
		}
		return super.eIsSet(featureID);
	}

} //PicoNetImpl
